/**
 * Copyright (c) 2015—2017 Zerone.Co.Ltd. All rights reserved.
 */
package com.zerone.pay.trade.enums;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 *
 * @author glassescat <a href="">零一零一科技</a>
 */
public enum TradeStatusEnum {

    processing("processing", "处理中"),

    refunding("refunding", "退款中"),

    refund("refund", "已退款"),

    revoking("revoking", "撤销中"),

    revoked("revoked", "已撤销"),

    fail("fail", "失败"),

    success("success", "成功");

    /** 枚举值 */
    private final String code;

    /** 枚举描述 */
    private final String message;

    public static Map<String, String> mapping() {
        Map<String, String> map = Maps.newLinkedHashMap();
        for (TradeStatusEnum type : values()) {
            map.put(type.getCode(), type.getMessage());
        }
        return map;
    }

    /**
     *
     * @param code 枚举值
     * @param message 枚举描述
     */
    TradeStatusEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * @return Returns the code.
     */
    public String getCode() {
        return code;
    }

    /**
     * @return Returns the message.
     */
    public String getMessage() {
        return message;
    }

    /**
     * @return Returns the code.
     */
    public String code() {
        return code;
    }

    /**
     * @return Returns the message.
     */
    public String message() {
        return message;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code
     * @return TradeStatusEnum
     */
    public static TradeStatusEnum getByCode(String code) {
        for (TradeStatusEnum _enum : values()) {
            if (_enum.getCode().equals(code)) {
                return _enum;
            }
        }
        return null;
    }

    /**
     * 获取全部枚举
     *
     * @return List<TradeStatusEnum>
     */
    public static java.util.List<TradeStatusEnum> getAllEnum() {
        java.util.List<TradeStatusEnum> list = new java.util.ArrayList<TradeStatusEnum>(values().length);
        for (TradeStatusEnum _enum : values()) {
            list.add(_enum);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public static java.util.List<String> getAllEnumCode() {
        java.util.List<String> list = new java.util.ArrayList<String>(values().length);
        for (TradeStatusEnum _enum : values()) {
            list.add(_enum.code());
        }
        return list;
    }

    /**
     * 通过code获取msg
     * @param code 枚举值
     * @return
     */
    public static String getMsgByCode(String code) {
        if (code == null) {
            return null;
        }
        TradeStatusEnum _enum = getByCode(code);
        if (_enum == null) {
            return null;
        }
        return _enum.getMessage();
    }

    /**
     * 获取枚举code
     * @param _enum
     * @return
     */
    public static String getCode(TradeStatusEnum _enum) {
        if (_enum == null) {
            return null;
        }
        return _enum.getCode();
    }
}